/**
 * 
 */
package net.homelinux.ajay.net.ondisk.view.dialogs.client;

import net.homelinux.ajay.net.ondisk.view.client.AppTree;
import net.homelinux.ajay.net.ondisk.view.client.AppTreeItem;
import net.homelinux.ajay.net.ondisk.view.client.FolderTreeItem;

import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * @author ajay
 *
 */
public abstract class AddNodeDlg extends AppDialogBox {

  private VerticalPanel p;
  private TextBox textBox;

//  /**
//   * 
//   */
//  public AddNode() {
//    init();
//  }

  /**
   * @param autoHide
   */
  public AddNodeDlg() {
    super(false);
    init();
  }

  private void init() {

    AppTreeItem parent = (AppTreeItem) AppTree.getTree().getSelectedItem();
    setPopupTop( parent.getAbsoluteTop()+parent.getOffsetHeight());
    setText("Add "+getNodeTypeString());
    this.setWidget(makePanel());
  }

  
  private Widget makePanel() {
    p = new VerticalPanel();
    p.add(new Label("Name of "+ getNodeTypeString() ));
    textBox = new TextBox();
    p.add(textBox);
    p.add(new OkCancelPanel(this){

      public void onCancel() {
        AddNodeDlg.this.onCancel();
      }

      public void onOk() {
        AddNodeDlg.this.onOk();
      }});
    return p;
  }


  public String getValue(){
    return textBox.getText();
  }
  
  protected abstract String getNodeTypeString() ;

  public void onOk() {
    dismiss();
    
  }
  
  protected void onCancel() {
    dismiss();
  }

  private void dismiss() {
    hide();
  }

}
